const app = getApp()
var QQMapWX = require('../../lib/js/qqmap-wx-jssdk.js');
var qqmapsdk;
Component({
  data: {
     naviShow: false,
     costomerPhone:wx.getStorageSync('phone') || ''
  },
  properties: {
    currentRoute: String,
  },
  attached() {
    this.setData({
      redNum:app.globalData.myRedNum
    })
    this.getIndexInfo()
  },

  methods: {
    jump: function (e) {
      console.log(app.globalData.store_id)
      if (e.currentTarget.dataset.route == this.properties.currentRoute) {
        return
      }
      if (e.currentTarget.dataset.route == 'shop/pages/home/home') {
        if (app.globalData.store_id && app.globalData.store_id != 1) {
          wx.reLaunch({
            url: '/' + e.currentTarget.dataset.route + '?store_id=' + app.globalData.store_id
          })
        } else {
          wx.navigateTo({
            url: '/shop/pages/shopGift/shopGift'
          })
        }
      } else {
        wx.reLaunch({
          url: '/' + e.currentTarget.dataset.route
        })
      }


    },
    toGation(){
      wx.openLocation({
        latitude:31.342085,
        longitude:120.943232,
        scale: 18,
        name: '江苏鸿鑫智能制造有限公司',
        address: '江苏鸿鑫智能制造有限公司'
      })
      return
      let key="WCUBZ-YYHLW-TDWR3-YYUSM-LV4VT-S4BFN"
      let referer = "鸿鑫智造-小程序线路导航"
      let endPoint = JSON.stringify({
          name: "江苏鸿鑫智能制造有限公司",
          latitude:31.342085,
          longitude:120.943232
      })
      wx.navigateTo({
        url: 'plugin://routePlan/index?key=' + key +'&referer=' + referer + '&endPoint=' + endPoint
      })
//         let plugin = requirePlugin('routePlan');

// let endPoint = JSON.stringify({  //终点
//     'name': '吉野家(北京西站北口店)',
//     'latitude': 39.89631551,
//     'longitude': 116.323459711
// });
// wx.navigateTo({
//     url: 'plugin://routePlan/index?key=' + key + '&referer=' + referer + '&endPoint=' + endPoint
// });

    },
    getNaviShow(e){
      let that = this
      let platform = wx.getDeviceInfo().system //判断使用设备
      
      if (platform.includes('iOS') || platform.includes('IOS') || platform.includes('ios')) {
        wx.makePhoneCall({
            phoneNumber: e.currentTarget.dataset.phone,
        })
      } else {
        that.setData({
          naviShow: true,
        })
      }
      return
      // if()
      
    },
    getIndexInfo(){
      let that = this
      app.fly.get('/ma/home/init').then(function (res) {

        if (res.code === 0) {
             that.setData({
              costomerPhone:res.data.telephone,

             })
        } 
      })
    },  
    makeCall(e){
       // 调用微信的拨打电话API 安卓直接跳转到手机拨号页面  苹果要用户点击同意才跳转
       wx.makePhoneCall({
           phoneNumber: e.currentTarget.dataset.phone,
       })
    },
    cancelShow(){
      this.setData({
        naviShow: false,
      })
    }
  }

})
